#include <cusp/blas.h>
#include <cusp/array2d.h>
#include <cusp/print.h>
#include <iostream>
#include <cusp/arithmetic_operators.h>

int main(void)
{
    // initialize x vector
    cusp::array1d<float, cusp::device_memory> x(2);
    x[0] = 1;
    x[1] = 2;

    // initialize y vector
    cusp::array1d<float, cusp::device_memory> y(2);
    y[0] = 3;
    y[1] = 4;

    cusp::print(x);
    cusp::print(y);
    x = (x + y);
    cusp::print(x);

    cusp::array1d<float, cusp::device_memory> a(2e6,1);
    cusp::array1d<float, cusp::device_memory> b(2e6,2);

    cudaEvent_t start,end;
    cudaEventCreate(&start);
    cudaEventCreate(&end);
    cudaEventRecord (start, 0);
    float f = 3.0f+4.0f;
    b = ((((a + b) + a) + (a + b)) + 3.0f) + (a + 3.0f) + (3.0f + f);
    cudaEventRecord (end, 0);
    cudaEventSynchronize(end);
    float ms;
    cudaEventElapsedTime (&ms, start, end);
    std::cout << ms <<"ms for b = b + a" << std::endl;

    cudaEventRecord (start, 0);
    cusp::blas::axpy(a,b,1);
    cudaEventRecord (end, 0);
    cudaEventSynchronize(end);
    cudaEventElapsedTime (&ms, start, end);
    std::cout << ms <<"ms for axpy" << std::endl;
    return 0;
}
